﻿using System.Drawing;
using System.Windows.Forms;

namespace Games.Classes
{

	public class GameForm : Form
	{
		protected const int MAX_LEVEL_SCORE = 25;
		protected const int MAX_LEVEL = 15;
		protected const int STARTING_LEVEL = 1;
		protected const int STARTING_LIVES = 3;

		protected bool GameOver;
		protected bool LevelUp;
		protected bool Paused;
		protected int Level = 1;
		protected Board Board;
		protected int Score;
		protected int CurrentLives;

		//public GameForm()
		//{
		//	Paint += 
		//}

		protected void NextLevel()
		{
			CurrentLives++;
			LevelUp = true;
			Invalidate();
		}

		protected void Gameover()
		{
			CurrentLives--;
			GameOver = true;
			Invalidate();
		}

		protected void DrawBackGround(Graphics canvas, int width, int height)
		{
			BackColor = Board.BackGroundColor;
			foreach (var barrier in Board.Barriers)
			{
				canvas.FillRectangle(new SolidBrush(Board.BarrierColor), new Rectangle(barrier.X * 16, barrier.Y * 16, 16, 16));
			}
			if (LevelUp || GameOver || Paused)
			{
				string line1 = "Level Up!";
				string line2 = string.Format("Next Level [{0}]", Level + 1);
				string line3 = string.Format("Press Enter to Continue to Level [{0}]", Level + 1);
				if (Level == MAX_LEVEL || GameOver)
				{
					line1 = GameOver ? "Game Over!" : "You Win!";
					line2 = string.Format("Final Level [{0}]  Final Score [{1}]", Level, Score * Level);
					if (CurrentLives > 0 && GameOver)
					{
						line3 = string.Format("Press Enter to Restart Level [{0}]", Level);
					}
					else
					{
						line3 = "Press Enter to Start a New Game";
					}
				}
				if (Paused)
				{
					line1 = "Paused";
					line2 = "";
					line3 = "";
				}
				SizeF message = canvas.MeasureString(line1, Font);
				// ReSharper disable PossibleLossOfFraction
				canvas.DrawString(line1, Font, new SolidBrush(Board.TextColor), new PointF((width - message.Width) / 2, height / 2));
				message = canvas.MeasureString(line2, Font);
				canvas.DrawString(line2, Font, new SolidBrush(Board.TextColor), new PointF((width - message.Width) / 2, (height / 2) + 20));
				message = canvas.MeasureString(line3, Font);
				canvas.DrawString(line3, Font, new SolidBrush(Board.TextColor), new PointF((width - message.Width) / 2, (height / 2) + 40));
				// ReSharper restore PossibleLossOfFraction
			}
		}
	}

}
